/**
 * 
 */
package net.jadoth.sqlengine.internal.tables;

import net.jadoth.sqlengine.SQL;


/**
 * @author Thomas Muenz
 *
 */
public class SqlQualifiedIdentityWithAlias extends SqlQualifiedIdentity
{
	
	
	public SqlQualifiedIdentityWithAlias(final String schema, final String name, final String alias) {
		super(new Sql(schema, name, SQL.util.escapeReservedWord(((alias!=null)?alias:SQL.util.guessAlias(name)))));
	}
	
	public SqlQualifiedIdentityWithAlias(final Sql sql)
	{
		super(sql);
	}
	
	
	@Override
	public Sql sql()
	{
		return (Sql)super.sql();
	}
	
	/**
	 * The Class Sql.
	 */
	public static class Sql extends SqlQualifiedIdentity.Sql
	{
		/** The alias. */
		public final String alias;

		/**
		 * Instantiates a new sql.
		 *
		 * @param sqlSchema the sql schema
		 * @param sqlName the sql name
		 * @param sqlAlias the sql alias
		 */
		protected Sql(final String sqlSchema, final String sqlName, final String sqlAlias) 
		{
			super(sqlSchema, sqlName);
			// (12.08.2009)FIXME: check strings for SQL keywords (i.e. Alias "OR" etc)
			this.alias = sqlAlias;
		}
		
//		/**
//		 * @return
//		 * @see java.lang.Object#toString()
//		 */
//		@Override
//		public String toString() {
//			return this.getClass() +": "+this.schema+", "+this.name+", "+this.alias;
//		}
	}

}
